<template>
  <a-drawer :title="`配货列表`" width="70%" :visible="visible"
            hide-cancel
            @cancel="visible = false"
            :footer="false"
            v-if="visible">
    <ma-crud ref="crudRef" :columns="columns" :options="shipmentOptions">
      <template #tableButtons>
        <a-button type="primary" status="success">
          <icon-plus/>
          添加
        </a-button>
        <a-button type="primary" v-show="status==1">
          <icon-edit/>
          一键配货
        </a-button>
        <a-button type="primary" status="danger" v-show="status==1">
          <icon-delete/>
          移除
        </a-button>
      </template>
    </ma-crud>
  </a-drawer>
</template>
<script setup>

import {inject, ref,reactive} from "vue";
import shipmentContainer from "@/api/document/shipmentContainer.js";
import dicthelper from "@/utils/dicthelp.js";

const crudRef = ref()
const record = inject('record')
const visible = defineModel()
const status = ref("1")
const shipmentOptions = ref({
  id: 'shipment_container',
  rowSelection: {showCheckedAll: true},
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  pageLayout: 'fixed',
  pk: 'id',
  api: shipmentContainer.getList,
  requestParams: {
    container_id: record.value.id,
  },
  tabs:{
    dataIndex:'status',
    onChange: (key) => {
      status.value = key
      console.log(status.value)
    }
  },
  add: {
    show: true,
    api: shipmentContainer.save,
    auth: ['document:shipmentContainer:save']
  },
  edit: {
    show: true,
    api: shipmentContainer.update,
    auth: ['document:shipmentContainer:update']
  },
  delete: {
    show: true,
    api: shipmentContainer.deletes,
    auth: ['document:shipmentContainer:delete']
  }
})
const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "select",
    dict: {
      name: "ShipmentContainerType",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
      },
    search: true,
  },
  {
    title: "用户",
    dataIndex: "user_id",
    formType: "select",
    dict: dicthelper.customer,
    search: true,
  },
  {
    title: "运单号",
    dataIndex: "shipment.shipment_no",
  },
  {
    title: "客户体积",
    dataIndex: "shipment.volume_weight.client_volume",
  },
  {
    title: "实际体积",
    dataIndex: "shipment.volume_weight.actual_volume",
  },
  {
    title: "提单号",
    dataIndex: "container.number",

  },
  {
    title: "创建者",
    dataIndex: "created_by",
    dict: {
        url: 'system/user/list',
        props: {label: 'nickname', value: 'id'} ,
        params: {select: 'id,nickname'},
        translation: true,
      },  
    formType: "select",
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    dict: {
        url: 'system/user/list',
        props: {label: 'nickname', value: 'id'} ,
        params: {select: 'id,nickname'},
        translation: true,
      },  
    formType: "select",
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    search: true,
    formType: "range",
    showTime: true,
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
  }
])
</script>